package test_unitaire;

import static org.junit.Assert.assertTrue;

import java.util.Calendar;

import org.junit.Test;

import buisness_service.Depense;
import buisness_service.PosteDepense;
import buisness_service.Rapport;
import buisness_service.Rapport.Mois;
import buisness_service.User;

public class Test_depense {

	@Test
	public void testDepenseFloatCalendarUser() {

		User u = new User();
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.APRIL, 12);
		Depense dep = new Depense(35, d, u);
		assertTrue(d.get(2) == 3);
		assertTrue(d.get(1) == 2009);
		assertTrue(dep.getId() ==Rapport.nbEntities);
		assertTrue(dep.getMontant() == 35);
		assertTrue(dep.getUser().getDepenses().get(0) == dep);
		assertTrue(dep.getUser().getEconomie().getMontant() == -35);
		assertTrue(dep.getDepense_jour().getFinance_jour().getFinance_mois()
				.getIndexFinance_annee() == 0);
		assertTrue(dep.getDepense_jour().getFinance_jour().getFinance_mois()
				.getIndex_finance_mois() == 0);
		assertTrue(dep.getDepense_jour().getFinance_jour()
				.getIndex_finance_jour() == 0);

		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getDep_mois().getDepenses_jour().get(0).getDepenses().get(0) == dep);
		PosteDepense transport = new PosteDepense("transport");
		transport.getSous_categorie().add("essence");
		d.set(2019, Calendar.APRIL, 12);
		Depense dep2 = new Depense(transport.getSous_categorie().get(0), 35, d,
				transport, u);

		assertTrue(dep2.getNom() == "essence");
		assertTrue(u.getRapport().get(1).getFinances_mois().get(0)
				.getDep_mois().getDepenses_jour().get(0).getDepenses().get(0) == dep2);
		assertTrue(u.getRapport().get(1).getDepense_annee()
				.getDepenses_mois().get(0).getDepenses_jour().get(0)
				.getDepenses().get(0) == dep2);
		

		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();

	}

	@Test
	public void testDepenseFloatCalendarPosteDepenseUser() {

		User u = new User();
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);

		PosteDepense transport = new PosteDepense("transport");
		transport.getSous_categorie().add("essence");
		Depense dep = new Depense(transport.getSous_categorie().get(0), 35, d,
				transport, u);
		assertTrue(dep.getId() == Rapport.nbEntities);
		assertTrue(dep.getMontant() == 35);
		assertTrue(dep.getUser().getDepenses().get(0) == dep);
		assertTrue(dep.getUser().getEconomie().getMontant() == -35);

		assertTrue(dep.getPosteDepense().getDepenses().get(0) == dep);

		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getDep_mois().getDepenses_jour().get(0).getDepenses().get(0) == dep);


		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();

	}

	@Test
	public void testDepense_Depense_Mois() {

		User u = new User();
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.APRIL, 12);

		Depense dep = new Depense(35, d, u);
		Calendar d2 = Calendar.getInstance();
		d2.set(2009, Calendar.APRIL, 13);
		Depense dep2 = new Depense(35, d2, u);

		assertTrue(d.get(2) == 3);
		assertTrue(d.get(1) == 2009);
		assertTrue(dep2.getId() == Rapport.nbEntities);
		assertTrue(dep.getMontant() == 35);
		assertTrue(dep.getUser().getDepenses().get(0) == dep);

		assertTrue(dep.getUser().getEconomie().getMontant() == -70);
		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getMois() == Mois.Avril);
		assertTrue(u.getRapport().get(0).getAnnee() == 2009);
		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getDep_mois().getDepenses_jour().get(0).getDepenses().get(0) == dep);
		assertTrue(dep2.getDepense_jour().getFinance_jour().getJour() == 13);
		assertTrue(dep.getDepense_jour().getFinance_jour().getJour() == 12);

		assertTrue(dep.getDepense_jour().getFinance_jour()
				.getIndex_finance_jour() == 0);
		assertTrue(dep2.getDepense_jour().getFinance_jour()
				.getIndex_finance_jour() == 1);

		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getFinances_jour().get(1).getJour() == 13);

		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getFinances_jour().get(1).getDep_jour().getDepenses().size() == 1);
		assertTrue(u.getRapport().get(0).getFinances_mois().get(0)
				.getFinances_jour().get(1).getDep_jour().getDepenses().get(0) == dep2);
		;
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

}
